import { defineStore } from "pinia";
import { PatientStoreState, PatientDiagInfo } from "@/types/patient";

export const usePatientStore = defineStore("patientStore", {
  state: (): PatientStoreState => ({
    patients: [],
  }),
  actions: {
    //添加新患者
    addPatient(patient: PatientDiagInfo) {
      this.patients.push(patient);
    },
    updatePatient(patientId: number, recordId: number) {
      const patient = this.patients.find((p) => {
        p.patientId === patientId;
      });
      if (patient) {
        patient.recordId = recordId;
      }
    },
    findPatientByIdCard(idCard: string) {
      return this.patients.find((p) => {
        p.idCard === idCard;
      });
    },
    clearPatients() {
      this.patients = [];
    },
  },
});
